<!--
* @Description: 监控点配置 -> 结构配置
* @Author: yihua
* @Date: 2023/3/29 18:35
* @LastEditTime: 2023/3/29 18:35
-->
<template>
  <div class="carnbon-container">

    <el-breadcrumb separator="/" style="padding:0px 20px 10px">
      <el-breadcrumb-item  :to="'/carbon/monitoring/index'">监控点配置</el-breadcrumb-item>
      <el-breadcrumb-item :to="'/carbon/monitoring/config'">总监控点配置</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form inline :model="searchFromData" class="configure-form">
      <el-card class="box-card" :header="'基本信息'">
        <el-form-item label="监控点名称" prop="code">
          <el-input v-model.trim="searchFromData.code" placeholder="请输入监控点名称" />
        </el-form-item>
      </el-card>
      <el-card class="box-card carbon-config-card" :header="'能源配置'">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="电力消耗量">
              <div class="formula_container iotInput" id="1" @click="openFormula(1,algorithmInput[0])">
                <span class="formula_content">
                  <span class="formula_show"  ref="algorithmInputRef" v-html="algorithmInput[0]">
                  </span>
                </span>
                <el-tooltip  :content="algorithmArr[0]" placement="top" popper-class="space-auth-status-tip" v-if="algorithmArr[0]">
                  <span><el-icon class="el-icon&#45;&#45;right" :size="18" style="margin-top:5px;"><Warning /></el-icon></span>
                </el-tooltip>
                <span v-else><el-icon class="el-icon--right" :size="18" style="margin-top:5px;"><Warning /></el-icon></span>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="蒸汽消耗量">
              <div class="formula_container iotInput" id="2" @click="openFormula(2,algorithmInput[1])">
                <span class="formula_content">
                  <span class="formula_show"  ref="algorithmInputRef" v-html="algorithmInput[1]">
                  </span>
                </span>
                <el-tooltip  :content="algorithmArr[0]" placement="top" popper-class="space-auth-status-tip" v-if="algorithmArr[1]">
                  <span><el-icon class="el-icon&#45;&#45;right" :size="18" style="margin-top:5px;"><Warning /></el-icon></span>
                </el-tooltip>
                <span v-else><el-icon class="el-icon&#45;&#45;right" :size="18" style="margin-top:5px;"><Warning /></el-icon></span>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="水消耗量">
              <div class="formula_container iotInput" id="3" @click="openFormula(3,algorithmInput[2])">
                <span class="formula_content">
                  <span class="formula_show"  ref="algorithmInputRef" v-html="algorithmInput[2]">
                  </span>
                </span>
                <el-tooltip  :content="algorithmArr[0]" placement="top" popper-class="space-auth-status-tip" v-if="algorithmArr[1]">
                  <span><el-icon class="el-icon&#45;&#45;right" :size="18" style="margin-top:5px;"><Warning /></el-icon></span>
                </el-tooltip>
                <span v-else><el-icon class="el-icon&#45;&#45;right" :size="18" style="margin-top:5px;"><Warning /></el-icon></span>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="压缩空气消耗量">
              <div class="formula_container iotInput" id="4" @click="openFormula(4,algorithmInput[3])">
                <span class="formula_content">
                  <span class="formula_show"  ref="algorithmInputRef" v-html="algorithmInput[3]">
                  </span>
                </span>
                <el-tooltip  :content="algorithmArr[3]" placement="top" popper-class="space-auth-status-tip" v-if="algorithmArr[3]">
                  <span><el-icon class="el-icon&#45;&#45;right" :size="18" style="margin-top:5px;"><Warning /></el-icon></span>
                </el-tooltip>
                <span v-else><el-icon class="el-icon&#45;&#45;right" :size="18" style="margin-top:5px;"><Warning /></el-icon></span>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>

      <el-card class="box-card" :header="'碳排放配置'">
        <el-radio-group v-model="boundary">
          <el-radio-button label="主体边界排放" />
          <el-radio-button label="履约边界排放" />
          <el-radio-button label="配额边界" />
        </el-radio-group>
        <correlateFormula :boundaryNumber="1" v-show="boundary=='主体边界排放'"></correlateFormula>
        <correlateFormula :boundaryNumber="2" v-show="boundary=='履约边界排放'"></correlateFormula>
        <correlateFormula :boundaryNumber="3" v-show="boundary=='配额边界'"></correlateFormula>
      </el-card>

      <formula ref="formulaFormRef" @changeAlgorithmInput="changeAlgorithmInput"/>

      <footer class="monitoring-footer">
        <el-button @click="onBack">返回</el-button>
        <el-button type="primary" @click="onSave">保存</el-button>
      </footer>
    </el-form>
  </div>
</template>
<script setup lang="ts">
  import CustomTableThird from '@/components/CustomTableThird.vue';
  import { getCurrentInstance, ref, defineEmits } from 'vue';
  import { useRouter } from 'vue-router';
  import { delHtmlTag } from '@/utils/stringUtils';
  type FormInstance = InstanceType<typeof ElForm>;
  const { ctx , proxy } = getCurrentInstance() as any;
  const activeName = ref('authApply')
  const checkedRows = ref([])

  import formula from './formula.vue'
  import correlateFormula from './correlateFormula.vue'

  let router = useRouter()

  const tableConfig = ref({})
  const isRefresh = ref(false)
  const boundary = ref('履约边界排放')
  const searchFromData = ref({
    name:'',
    projectId:''
  })

  const go = (path: string) => {
    router.push({
      path:path
    })
  }
  const onBack = () => { go('/carbon/monitoring/index')}
  const onSave = () => { go('/carbon/monitoring/index')}

  let rowNumber = 0;

  let algorithmArr = ref(['','','','']);
  let algorithmInput = ref(['','','','']);
  // 从子组件接收过来的值
  const changeAlgorithmInput = (e) =>{
    console.log('从子组件接收过来的值',e);
    algorithmInput.value[(e.rowNumber -1)] = e.value;
    algorithmArr.value[ (e.rowNumber -1)] = delHtmlTag(e.value);
  }

  const formulaFormRef = ref(null)
  const openFormula = (row) => {
    console.log('row',row);
    formulaFormRef.value && formulaFormRef.value.open(row);
  }
</script>
<style lang="scss" scoped>
  :deep{
    .configure-form {
      padding:10px 20px;
      .el-card{
        margin-bottom: 15px;
      }
      .el-card__header {
        padding:10px ;
        font-size: 14px;
        background: #f9f9f9;
        border-left: 3px solid #0080ff;
        border-radius: 3px;
      }
      .el-card__body {
        padding-top: 15px;
        padding-bottom:0px;
      }
    }
  }
  .formula_container{
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 36px;
    padding: 4px 11px;
    line-height: 1.5715;
    background: #fff;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    cursor: pointer;
  }
  .formula_content {
    display: flex;
    align-items: center;
  }
  .monitoring-footer{
    position: fixed;
    bottom:0;
    left:235px;
    right:0;
    z-index: 10;
    width: auto;
  }
</style>
<style lang="scss">
  .carbon-config-card{
    .el-form-item{
      display: flex;
      flex-direction: column !important;
      .el-form-item__content {
        padding-left: 0 !important;
      }
    }

    .el-form--inline .el-form-item {
      display: flex;
      vertical-align: middle;
      margin-right: 1.66667rem;
      flex-direction: column !important;
      padding-left: 3px;
      justify-content: flex-start;
    }
    .el-form-item__label{
      display: flex;
      justify-content: flex-start;
    }
  }
</style>